package gameObject;

import javax.microedition.lcdui.Graphics;

import main.Res;

import base.AlignMapObject;


public class Hero extends Unit implements AlignMapObject{
	protected int settleX;
	protected int settleY;
	protected int repawnTime=0;
	public Hero()
	{
		super(0,50+Res.getRandom(10),
				50+Res.getRandom(50),
				50+Res.getRandom(10),
				50+Res.getRandom(50)); // id att def speed range 
		//repawnTime = 100;
	}
	public Hero(int att,int def,int sp,int r)
	{
		super(0,att,def,sp,r); // id att def speed range 
		//repawnTime = 100;
	}
	public int getArmId(){
		if(arm== null){
			return -1;
		}
		return arm.getId();
	}
	public int getSuitId(){
		if(suit== null){
			return -1;
		}
		return suit.getId();
	}
	public void setMapIndex(int i, int j) {
		setPosition(15 + i*30, 15 + j*30);
		
		settleX = 15 + i*30;
		settleY = 15 + j*30;
	}
	public void idle()
	{
		setPosition(settleX, settleY);
	}
	public void moveToSettle()
	{
		if(getX() != settleX||getY() != settleY){
			moveTo(settleX, settleY);
		}else{
			setRotation(0);
		}
	}
	public boolean inRange(Monster monster){
		if((arm == null) || (monster.isAir() && !arm.isAir())){
			return false;
		}
			
		return dist(settleX, settleY, monster.getX(),monster.getY())<range;
	}
	public int getRowIndex() {
		return settleY/30;
		
	}
	public int getColIndex() {
		return settleX/30;
	}
	public void paint(Graphics g){
		sprite.paint(g);
		if(arm != null){
			arm.paint(g);
		}
		if(suit != null){
			suit.paint(g);
		}
	}
	public void resetRepawnTime(){
		repawnTime = defend*2;
	}
	public boolean countRepawnTime(){
		if(repawnTime == 0){
			return true;
		}
		repawnTime--;
		return false;
	}
	public void uplevel(){
		attack+= Res.getRandom(3);
		defend+= Res.getRandom(3);
		speed+= Res.getRandom(3);
		range+= Res.getRandom(4);
	}
}
